import Notify from '../../miniprogram_npm/@vant/weapp/notify/notify';

function get_data(username, password, weeks, that, app) {
  wx.request({
    url: 'https://hongzhe.xyz/course',
    method: "POST",
    dataType: "json",
    data: {
      "username": username,
      "password": password,
      "weeks": weeks
    },
    success: function (res) {
      app.globalData.name = res.data['姓名'];

      // 新增代码--
      const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
      const classes = [1, 3, 5, 7, 9];

      let course_info_data = {};

      days.forEach(day => {
        classes.forEach(cls => {
          if (JSON.stringify(res.data['data'][day][cls]) === JSON.stringify({})) {
            course_info_data[`${day.slice(0, 3)}${cls}`] = "";
          }else
          {
            course_info_data[`${day.slice(0, 3)}${cls}`] = res.data['data'][day][cls];
          }

        });
      });

      that.setData(course_info_data);
      // 新增代码---
    }
  })
}
// 2104020320
Page({
  data: {
    show: false,

    array: ["第一周",
      "第二周",
      "第三周",
      "第四周",
      "第五周",
      "第六周",
      "第七周",
      "第八周",
      "第九周",
      "第十周",
      "第十一周",
      "第十二周",
      "第十三周",
      "第十四周",
      "第十五周",
      "第十六周",
      "第十七周",
      "第十八周",
      "第十九周",
      "第二十周"
    ],
    index: 0,
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var app = getApp()
    var password = app.globalData.password
    var username = app.globalData.username
    var weeks = app.globalData.weeks

    wx.showLoading({
      title: '加载中',
    })
    setTimeout(function () {
      wx.hideLoading() && get_data(username, password, weeks, that, app);
    }, 1500)




    Notify({
      type: 'success',
      message: `第${weeks}周课表`
    });
  },

  get_weeks: function getCurrentWeek() {
    //这里设置第一周/第一天的日期
    var baseDate = Date.parse("2021-03-08")
    var nowDate = Date.parse(new Date())

    var duringTime = nowDate - baseDate
    var weekTimestamp = 7 * 24 * 60 * 60 * 1000

    var currentWeek = 0
    var week = duringTime / weekTimestamp

    if (Number.parseFloat(week) - Number.parseInt(week) == 0) {
      currentWeek = week + 1
    } else {
      //如果week不是整数，向上取整即可
      currentWeek = Math.ceil(week)
    }
    return currentWeek
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {


  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {


  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {


  },


  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {


  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {


  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {


  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  showPopup() {
    this.setData({
      show: true
    });
  },

  onClose() {
    this.setData({
      show: false
    });
  },

  onConfirm(event) {
    const {
      picker,
      value,
      index
    } = event.detail;
    console.log(value, index);
  },

  onCancel() {
    wx.showToast({
      title: '取消',
    })
  },
  mon1: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Mon1,
      showCancel: false
    })
  },

  mon3: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Mon3,
      showCancel: false
    })
  },

  mon5: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Mon5,
      showCancel: false
    })
  },
  mon7: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Mon7,
      showCancel: false
    })
  },
  mon9: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Mon9,
      showCancel: false
    })
  },
  mon11: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Mon11,
      showCancel: false
    })
  },
  tue1: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Tue1,
      showCancel: false
    })
  },
  tue3: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Tue3,
      showCancel: false
    })
  },
  tue5: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Tue5,
      showCancel: false
    })
  },
  tue7: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Tue7,
      showCancel: false
    })
  },
  tue9: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Tue9,
      showCancel: false
    })
  },
  tue11: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Tue11,
      showCancel: false
    })
  },

  wed1: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Wed1,
      showCancel: false
    })
  },

  wed3: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Wed3,
      showCancel: false
    })
  },
  wed5: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Wed5,
      showCancel: false
    })
  },
  wed7: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Wed7,
      showCancel: false
    })
  },
  wed9: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Wed9,
      showCancel: false
    })
  },
  wed11: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Wed11,
      showCancel: false
    })
  },

  thu1: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Thu1,
      showCancel: false
    })
  },
  thu3: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Thu3,
      showCancel: false
    })
  },
  thu5: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Thu5,
      showCancel: false
    })
  },
  thu7: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Thu7,
      showCancel: false
    })
  },
  thu9: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Thu9,
      showCancel: false
    })
  },
  thu11: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Thu11,
      showCancel: false
    })
  },

  fri1: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Fri1,
      showCancel: false
    })
  },
  fri3: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Fri3,
      showCancel: false
    })
  },
  fri5: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Fri5,
      showCancel: false
    })
  },
  fri7: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Fri7,
      showCancel: false
    })
  },
  fri9: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Fri9,
      showCancel: false
    })
  },
  fri11: function () {
    wx.showModal({
      title: '课程详情',
      content: this.data.Fri11,
      showCancel: false
    })
  },
});